cmake_minimum_required(VERSION 3.16.3)

PROJECT(OCPP)

message(STATUS "compiler: " ${CMAKE_CXX_COMPILER_ID})

include(CheckIncludeFileCXX)
check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
check_include_file_cxx(coroutine HAS_COROUTINE)
if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
    set(DROGON_CXX_STANDARD ${CMAKE_CXX_STANDARD})
elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
    set(DROGON_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
    set(DROGON_CXX_STANDARD 17)
else ()
    set(DROGON_CXX_STANDARD 14)
endif ()


LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")

SET(CMAKE_DEBUG_POSTFIX d)
SET(WORKINGPATH ${CMAKE_CURRENT_SOURCE_DIR})

INCLUDE(OCMacroUtils)

OPTION(DYNAMIC_OCPP "Set to ON to build OCPP for dynamic linking.  Use OFF for static." ON)
IF   (DYNAMIC_OCPP)
    SET(OCPP_USER_DEFINED_DYNAMIC_OR_STATIC "SHARED")
ELSE ()
    SET(OCPP_USER_DEFINED_DYNAMIC_OR_STATIC "STATIC")
ENDIF()

SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
IF(WIN32)
    SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
    SET(OUTPUT_BINDIR ${CMAKE_CURRENT_SOURCE_DIR}/ocppwin32/bin)
    SET(OUTPUT_LIBDIR ${WORKINGPATH}/lib)
ELSE(WIN32)
    SET(OUTPUT_BINDIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
    SET(OUTPUT_LIBDIR ${WORKINGPATH}/bin)
ENDIF(WIN32)


SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_BINDIR})
IF(WIN32)
    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_BINDIR})
ELSE(WIN32)
    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR})
ENDIF(WIN32)

FOREACH(CONF ${CMAKE_CONFIGURATION_TYPES})        # For each configuration (Debug, Release, MinSizeRel... and/or anything the user chooses)
    STRING(TOUPPER "${CONF}" CONF)                # Go uppercase (DEBUG, RELEASE...)
    SET("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_LIBDIR}")
    SET("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_BINDIR}")
    IF(WIN32)
        SET("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_BINDIR}")
    ELSE()
        SET("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_LIBDIR}")
    ENDIF()
ENDFOREACH()

MESSAGE(STATUS "cxx standard: " ${DROGON_CXX_STANDARD})

IF(WIN32)
    SET(3RDPARTY_DIR ${WORKINGPATH}/ocppwin32/3rdparty)
ELSE(WIN32)
    SET(3RDPARTY_DIR "")
ENDIF(WIN32)


if(MSVC)
    add_compile_options(/wd4818 /wd4819 /wd4828)


    option(OC_BUILD_QT "" FALSE)
    SET(OC_QT_PATH "E:/Qt/Qt5.14.2/5.14.2/msvc2017_64" CACHE PATH "E:/Qt/Qt5.14.2/5.14.2/msvc2017_64")

    if (OC_BUILD_QT)
        message(STATUS "OC build qt application.")
        SET(CMAKE_PREFIX_PATH ${OC_QT_PATH})
        FIND_PACKAGE(Qt5Widgets REQUIRED)
        #IF ( Qt5Widgets_FOUND )
        #ENDIF( )
    endif ()
endif()

LINK_DIRECTORIES(${3RDPARTY_DIR}/lib)
LINK_DIRECTORIES(${OUTPUT_LIBDIR})
LINK_DIRECTORIES(${PROJECT_BINARY_DIR})
ADD_SUBDIRECTORY(${WORKINGPATH}/src)

